Hi guys!

maybe you can help me. i found old source back from 1999...
(it was really started for numen... do we really work since
1999 on numen? unbelievable...)

the idea is to have a really fast transparency fx. with this
we can blend 2 pictures in 16 degrees...

here is the basic idea:

main-function: color_new = color_pic1*t+color_pic2*(1-t)
t, c1,c2 : 0-15

so the main task is to compute the new vram out of the 2 pictures
and the transparence value:

main-loop:
 c1=image1[x,y]
 c2=image2[x,y]
 c=peek(transtab+c1+c2*16)
 screen[x,y]=c

here is the turbo basic source to generate the lookup transtab
each picture can have 0-15 value per pixel in mode9. so a standard
looptable with gets the c1+c2*16 will have 256 bytes. and as we
want to have 0-15 steps of transparence the loopuptable will be
have 4096 = 16*256. as you can see the c2*16 is unnecessary when
shifting one picture with 16. sorry i forgot to mention that
each picture will be in raw format and byte per pixel. so it can
be easily computed later on.

1 TAB=$4000
2 TT=0
3 FOR T=0 TO 15
4   FOR C2=0 TO 15
5     FOR C1=0 TO 15
6       A=C1*TT+C2*(1-TT)
7       POKE TAB+C1+C2*16+T*256,INT(A)
8       PRINT A
9     NEXT C1
10   NEXT C2
11   TT=TT+1/16
12   PRINT "+",TT
13 NEXT T
14 OPEN #1,8,0,"H:TRANSTAB.BIN"
15 BPUT #1,TAB,4096
16 CLOSE #1

to speed this up in assembler and to make it flexible as necessary
and fast as possible i had this ideas:

the rendering engine will work in this steps

0. set up the zeropage pointers
1. calculate the video buffer depending on the picture positions on screen
into the rendering buffer
2. render the buffer on depending of the transparence value
3. back to 0

i will try to explain that... 

0. set up the zeropage pointers

the rendering engine needs 60 pointers for picture1 and 60 pointers for picture2
each vector points to a desired line of the picture. remember each picture is stored
as byte per pixel (and picture2 is byte*16 per pixel). so i need 240 zero page adresses.

1. calculate the video buffer 

the buffer contains the offset for each pixel on screen (is it not called
alpha channel value???). this will be used by the rendering engine later.

the offset is offset=c1+c2*16. simple? yes it is...

so my speedcode looks like this:

	ldy	#0
	lda	(pic1),y	;get pixel from pic1
	ora	(pic2),y	;get pixel from pic2
	sta	buffer_lo	;store it in the low nibble
	iny
	lda	(pic1),y	;get pixel from pic1
	ora	(pic2),y	;get pixel from pic2
	sta	buffer_hi	;store it in the hi nibble
	iny
	...

this speedcode will compute 80x60 pixels. right now it seems that the speedcode
will take approx. 38400 bytes!!! (quite long, isn't?)

2. rendering the final screen

as we have build up the offset buffer, each for hi & lo nibble i build up again
a speed code routine:

* build screen

	ldy	buffer_hi	;get the offset on pixel position
	lda	(transtab_hi),y ;get the new pixel depending on transparence
	ldy	buffer_lo	;get the offset on pixel position+1
	ora	(transtab_lo),y
	sta	screen
	ldy	buffer_hi+1
	...

which takes quite loot ram, too...

you may ask why i am using 240 zero pages? whith the zero pages it will be possible to
make some fx on the source pictures, f.e. move, distort or other strange things...

what do you think of it? is it generall possible??? and how should it be used? f.e.
should i use the XE banks? f.e. the rendering engine could be fit into 1 rambank?
that makes sense. right now it seems that it will not fit into 1 frame so it must be
double buffered... and how many zeropage adresses are free in numen?

maybe you guys can help me...


Heaven





appendix a

* tansparence for numen
* by heaven/tqa
* 25,30/december 1999
* some infos:

* main-function: color_new = color_pic1*t+color_pic2*(1-t)
* t, c1,c2 : 0-15

*main-loop:
* c1=image1[x,y]
* c2=image2[x,y]
* c=peek(transtab+c1+c2*16)
* screen[x,y]=c

*one image must be shifted because of better indexing

*lda image1
*adc image2
*tax
*lda image1+1
*adc image2+1
*tay
*lda transtab,x
*ora transtab2,y
*sta screen



make_code ldy #59			;60 lines
	lda	#0
	sta	v1			;contains picture pointers
	mwa	#buffer_lo	si
	mwa	#buffer_hi	di
	mwa	#code	putcode+1

mc0	lda	#$a0			;ldy #0
	jsr	putcode
	lda	#0
	jsr	putcode
	ldx	#39			;40 bytes per line
mc1	lda	#$b1			;lda (),y
	jsr	putcode
	lda	v1			;get zero
	jsr	putcode
	lda	#$11			;ora (),y
	jsr	putcode
	lda	v1
	jsr	putcode
	lda	#$8d			;sta $ffff
	jsr	putcode
	lda	di
	jsr	putcode
	lda	di+1
	jsr	putcode
	lda	#$c8			;iny
	jsr	putcode
	lda	#$b1			;lda (),y
	jsr	putcode
	lda	v1			;get zero
	jsr	putcode
	lda	#$11			;ora (),y
	jsr	putcode
	lda	v1
	jsr	putcode
	lda	#$8d			;sta $ffff
	jsr	putcode
	lda	si
	jsr	putcode
	lda	si+1
	jsr	putcode
	lda	#$c8
	jsr	putcode
	dex
	bpl	mc1
	lda	v1
	add	#2
	sta	v1
	lda	si
	add	#40
	sta	si
	bcc	mc2
	inc	si+1
mc2	lda	di
	add	#40
	sta	di
	bcc	mc3
	inc 	di+1
mc3	dey
	bpl	mc0
	rts
	
putcode	sta	$4000
	inc	putcode+1
	bne	putcode1
	inc	putcode+2
putcode1 rts


appendix b

0 ------------------------------
1 REM TRANSPARENZ TEST
2 ------------------------------
5 GRAPHICS 9
10 PIC1=$4000
15 PIC2=$6000
16 TAB=$8000
20 OPEN #1,4,0,"H:MASK.RAW":BGET #1,PIC1,8192:CLOSE #1
25 OPEN #1,4,0,"H:DRACHE.RAW":BGET #1,PIC2,8192:CLOSE #1
27 OPEN #1,4,0,"H:TRANSTAB.BIN":BGET #1,TAB,4096:CLOSE #1
50 DO 
60   FOR TT=0 TO 15
70     EXEC DOTRANS
75   NEXT TT
80 LOOP 
999 DO :LOOP 
1000 PROC DOTRANS
1010   FOR J=0 TO 119
1020     FOR I=0 TO 79
1030       C1=PEEK(PIC1+I+J*80)
1040       C2=PEEK(PIC2+I+J*80)
1045       REM TT=INT(T*16) MOD 16
1050       C=PEEK(TAB+C1+C2*16+TT*256)
1060       C=INT(C MOD 16)
1070       COLOR C:PLOT I,J
1080     NEXT I
1090   NEXT J
1100 ENDPROC 
